# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Benoît Allard <benoit dot allard at gmx dot de>
# Contributor: killruana <killruana@gmail.com>

pkgname=yosys
pkgver=0.34
pkgrel=1
pkgdesc='A framework for RTL synthesis'
arch=('loong64' 'x86_64')
url='https://yosyshq.net/yosys/'
license=('custom:ISC')
depends=('abc' 'bash' 'boost-libs' 'tcl' 'libffi' 'python' 'protobuf')
makedepends=('boost')
checkdepends=('iverilog')
optdepends=('graphviz: Schematics display support'
            'xdot: Display netlists'
            'yices: default solver for yosys-smtbmc'
            'cvc4: alternative solver for yosys-smtbmc'
            'z3: alternative solver for yosys-smtbmc')
options=('!lto') # getting SIGSEGV when running the tests with LTO
source=("https://github.com/cliffordwolf/yosys/archive/$pkgname-$pkgver.tar.gz")
sha512sums=('abed6ba5dcc423b2d35026ab9a296d73671b9f0331415dc674770fca60b4244e7efb31d7c271485a41c9638522c8dc685096ebf832bff9fcb7af046261c19c07')

_make() {
    local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
    local python_version_combined=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
    make \
        PREFIX="/usr" \
        CONFIG=gcc \
        ENABLE_TCL=1 \
        ENABLE_ABC=1 \
        ENABLE_GLOB=1 \
        ENABLE_PLUGINS=1 \
        ENABLE_LIBYOSYS=1 \
        ENABLE_PROTOBUF=1 \
        ENABLE_ZLIB=1 \
        ENABLE_PYOSYS=1 \
        ABCEXTERNAL=abc \
        BOOST_PYTHON_LIB="-lpython${python_version} -lboost_python${python_version_combined}" $@
}

build() {
    cd $pkgname-$pkgname-$pkgver
    _make
}

check() {
    cd $pkgname-$pkgname-$pkgver
    _make test
}

package() {
    cd $pkgname-$pkgname-$pkgver
    _make DESTDIR="$pkgdir" PYTHON_PREFIX="$pkgdir/usr" install

    install -Dm644 COPYING -t "$pkgdir"/usr/share/licenses/$pkgname/
}
